﻿using MediatR;
using T_Rbac.Read.APi.Application.Command.OperatetorCommand;
using T_Rbac.Read.APi.Dto;
using T_Rbac_Rep.Interface;

namespace T_Rbac.Read.APi.Application.Handlers.OperatorHandlers
{
    public class OperatorLoginHandlers : IRequestHandler<OperatorLoginnUserCommand, LoginDto>
    {
        private readonly IOperator ioperator;

        public OperatorLoginHandlers(IOperator ioperator)
        {
            this.ioperator = ioperator;
        }

        public async Task<LoginDto> Handle(OperatorLoginnUserCommand request, CancellationToken cancellationToken)
        {
            var list = await ioperator.GetAloneByresult(x => x.Opwd.Equals(request.pwd) && x.Oname.Equals(request.name) && x.IsDel.Equals(false)&&x.Ostate==true);
            if (list!=null)
            {
                var lista = new LoginDto
                {
                    id = list.Oid,
                    token = ""
                };
                return await Task.FromResult(lista);
            }
            else
            {
                var lista = new LoginDto
                {
                    id = -1,
                    token = ""
                };
                return await Task.FromResult(lista);
            }
        }
    }
}
